namespace Maple.Branch.Identity.DefinitionProviders
{
    using Consts;
    using Localizations;
    using Volo.Abp.Authorization.Permissions;
    using Volo.Abp.Localization;

    public class IdentityPermissionProvider : PermissionDefinitionProvider
    {
        public override void Define(IPermissionDefinitionContext context)
        {
            var group = context.AddGroup(IdentityPermissionNames.GroupName, L("DN:Permission:Identity"));

            var rolesPermission = group.AddPermission(IdentityPermissionNames.Roles.Default, L("DN:Permission:Role"));
            rolesPermission.AddChild(IdentityPermissionNames.Roles.Create, L("DN:Permission:Create"));
            rolesPermission.AddChild(IdentityPermissionNames.Roles.Update, L("DN:Permission:Edit"));
            rolesPermission.AddChild(IdentityPermissionNames.Roles.Delete, L("DN:Permission:Delete"));
            rolesPermission.AddChild(IdentityPermissionNames.Roles.ManagePermissions, L("DN:Permission:ChangePermissions"));

            var usersPermission = group.AddPermission(IdentityPermissionNames.Users.Default, L("DN:Permission:User"));
            usersPermission.AddChild(IdentityPermissionNames.Users.Create, L("DN:Permission:Create"));
            usersPermission.AddChild(IdentityPermissionNames.Users.Update, L("DN:Permission:Edit"));
            usersPermission.AddChild(IdentityPermissionNames.Users.Delete, L("DN:Permission:Delete"));
            usersPermission.AddChild(IdentityPermissionNames.Users.ManagePermissions, L("DN:Permission:ChangePermissions"));

            group.AddPermission(IdentityPermissionNames.UserLookup.Default, L("DN:Permission:UserLookup"))
                .WithProviders(ClientPermissionValueProvider.ProviderName);
        }

        private static LocalizableString L(string name)
        {
            return LocalizableString.Create<IdentityLocalResource>(name);
        }
    }
}
